<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子组件向父组件传递数据</title>
</head>
<body>
<div id="app">
    <cpn v-on:cpn="infoReviced"></cpn>
</div>

<template id="cpn">
    <label for="info">发送内容</label><input type="text" name="info" id="info" v-model="info">
    <button v-on:click="btnClicked">发送</button>
</template>

<script type="module">
    import {createApp, defineComponent, ref} from "../../../js/vue.esm-browser.js";

    let component = defineComponent(
        {
            template: '#cpn',
            // emits 选项用来自定义消息
            emits: ['cpn'],
            setup(props, context) {
                let info = ref(null)

                function btnClicked() {
                    // 发送自定义消息
                    // emits 第一个参数为 自定义消息名称， 第二个参数为 消息的内容
                    context.emit("cpn", info.value)
                }

                return {
                    info, btnClicked,
                }
            }
        }
    );

    let app = createApp(
        {
            setup() {
                function infoReviced(event) {
                    console.log(event);
                }

                return {
                    infoReviced,
                }
            }
        }
    );

    app.component("cpn", component)

    app.mount("#app")
</script>
</body>
</html>